package com.huangliusong.demo;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController()
public class NetWorkController {
	@GetMapping("/send")
	public Object getCurrentUser(@RequestParam("password") String password, 
			@RequestParam("text") String text,
			@RequestParam("recipient") String recipient, 
			@RequestParam("encoding") String encoding) {
		return responseR(password, text, recipient);
	}

	public String responseR(String password, String text, String recipient) {
		if (password.equals("123456")) {
			if (recipient.contains(",")) {
				String[] phonses = recipient.split(",");
				for (int i = 0; i < phonses.length; i++) {
					System.err.println("消息【" + text + "】已发送到【" + phonses[i] + "】");
				}
			}else {
				System.err.println("消息【" + text + "】已发送到【" + recipient + "】");
			}
			return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n" + 
					"<send>\r\n" + 
					"<error>0</error>\r\n" + 
					"<message_status>SENT</message_status>\r\n" + 
					"<ref_no/>\r\n" + 
					"<msg_id>3</msg_id>\r\n" + 
					"<gateway>modem1</gateway>\r\n" + 
					"</send>";
		} else {
			
			return "<send>\r\n" + 
					"<error>-9002</error>\r\n" + 
					"<error_description>Message not sent.</error_description>\r\n" + 
					"<message_status>FAILED</message_status>\r\n" + 
					"<failure_cause>UNKNOWN</failure_cause>\r\n" + 
					"<ref_no/>\r\n" + 
					"<msg_id>4</msg_id>\r\n" + 
					"<gateway>*</gateway>\r\n" + 
					"</send>";
		}
	}
}
